//package com.stars.easyms.rest.handler;
//
//import com.stars.easyms.base.bridge.EasyMsUrlBlockHandler;
//import com.stars.easyms.rest.constant.RestConstant;
//import com.stars.easyms.rest.dto.EasyMsRequestDTO;
//import com.stars.easyms.rest.dto.BaseOutput;
//import com.stars.easyms.rest.dto.ResponseMsg;
//import org.springframework.lang.NonNull;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * <p>className: EasyMsRestUrlBlockHandler</p>
// * <p>description: 当rest接口被sentinel阻塞时的处理类</p>
// *
// * @author guoguifang
// * @version 1.2.2
// * @date 2019-07-26 20:07
// */
//@Slf4j
//public final class EasyMsRestUrlBlockHandler implements EasyMsUrlBlockHandler {
//
//    private final EasyMsRestRequestHandler easyMsRestRequestHandler;
//
//    @Override
//    public boolean blocked(HttpServletRequest request, HttpServletResponse response, Exception blockException) {
//        return easyMsRestRequestHandler.filter(request, response, (requestMsg, requestMappingPathForRestInfo) -> {
//            // 获取当前rest请求地址
//            String requestPath = requestMappingPathForRestInfo.getRequestMappingPath();
//
//            // 获取返回值
//            ResponseMsg<Object> responseMsg;
//            EasyMsRequestDTO easyMsRequestDTO = null;
//            try {
//                requestMsg = easyMsRestRequestHandler.decode(requestMsg, requestPath, requestMappingPathForRestInfo);
//                easyMsRequestDTO = easyMsRestRequestHandler.executeBefore(requestMsg, requestPath);
//                responseMsg = handleBlockExceptionResponseMsg(easyMsRequestDTO, requestPath);
//            } catch (Exception e) {
//                responseMsg = easyMsRestRequestHandler.handleExceptionResponseMsg(e, easyMsRequestDTO, requestPath);
//            }
//            return easyMsRestRequestHandler.executeAfter(responseMsg, requestMappingPathForRestInfo);
//        });
//    }
//
//    @NonNull
//    private ResponseMsg<Object> handleBlockExceptionResponseMsg(@NonNull EasyMsRequestDTO easyMsRequestDTO, @NonNull String requestPath) {
//        ResponseMsg<Object> responseMsg = new ResponseMsg<>();
//        BaseOutput baseOutput = easyMsRestRequestHandler.parseOutput(null, easyMsRequestDTO);
//        baseOutput.setRetCode(RestConstant.DEFAULT_ERROR_CODE);
//        baseOutput.setRetMsg(RestConstant.DEFAULT_REST_URL_BLOCK_MSG);
//        responseMsg.setResponseBody(baseOutput);
//        responseMsg.setErrorDesc(RestConstant.DEFAULT_REST_URL_BLOCK_ERROR_DESC);
//
//        // 如果responseMsg为空表示未记录日志，此处记录异常后的返回日志，
//        log.info("[接收服务-响应]--[请求路径:{}]--[交易流水:{}]--[响应数据]:{}", requestPath, easyMsRequestDTO.getTransNo(), responseMsg);
//        return responseMsg;
//    }
//
//    public EasyMsRestUrlBlockHandler(EasyMsRestRequestHandler easyMsRestRequestHandler) {
//        this.easyMsRestRequestHandler = easyMsRestRequestHandler;
//
//    }
//
//}